<?php
/*
 * inc-nav-menu.php
 * Retral/CSCD494 Winter 2009
 * Eastern Washington University
 *
 * File Description:
 * The navigation menu. This is populated from one of two tables in the database:
 * If admin/facul:
 * 	-Pulls pages and URLs from NAV_URLS based on their permission codes
 * If student:
 * 	-Pulls pages and URLs from STUDENT_URLS
 *
 * Other:
 * 
 */
?>

<?php
	//Force a home button to always exist
	echo "<a href=\"index.php\"><span class=\"menu-button\"><br>Home</span></a>";
	echo "<span class=\"nav-divider\">&nbsp;</span>";

	//If user is logged in, show dynamic urls relevent to user account type
	if ($_SESSION['loggedIn'] != "" && ($_SESSION['roleCode'] == "admin" || $_SESSION['roleCode'] == "faculty" || $_SESSION['roleCode'] = "student"))
	{
		/*define("ORA_CON_UN", "cscd494");             // username
		define("ORA_CON_PW", "R3tral435");             // password
		define("ORA_CON_DB", "//146.187.134.17:1542/oracle10g"); // connection string
*/
		$conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);

		if ($_SESSION['roleCode'] == "admin")
			$query = "SELECT PAGE_NAME, PAGE_URL FROM NAV_URLS WHERE ADMIN='1'";
		else if ($_SESSION['roleCode'] == "faculty")
			$query = "SELECT PAGE_NAME, PAGE_URL FROM NAV_URLS WHERE FACUL='1'";
		else if ($_SESSION['roleCode'] == "student")
			$query = "SELECT PAGE_NAME, PAGE_URL FROM STUDENT_URLS";
		else
			$query = ""; //SHOULD NOT EVER GET HERE, BUT PREVENTS NULL COMMANDS.
		$stmt = oci_parse($conn, $query);
		
		oci_execute($stmt);
		
		while($nav_array = oci_fetch_array($stmt)) {
			echo "<a href=\"" . $nav_array[1] . "\"><span class=\"menu-button\"><br>" . $nav_array[0] ."</span></a>";
			echo "<span class=\"nav-divider\">&nbsp;</span>";
		} //end while
		
		oci_close($conn);
	} //end if


	if ($_SESSION['loggedIn'] != "")
		echo "<a href=\"logout.php\"><span class=\"menu-button\"><br>Logout</span></a>";
	else
		echo "<a href=\"?page=login\"><span class=\"menu-button\"><br>Login</span></a>";
	
	
	echo "<span class=\"nav-divider\">&nbsp;</span>";

?>
